# Run in phpMyAdmin or Whatever You're Using to Reach your Database Panel:
CREATE TABLE IF NOT EXISTS `chats` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `subject` VARCHAR(90) NOT NULL, `message` TEXT NOT NULL, `user_id` INT UNSIGNED NOT NULL, `assigned_to` INT UNSIGNED NULL, `department_id` INT UNSIGNED NOT NULL, `is_read` TINYINT UNSIGNED NOT NULL DEFAULT '0', `is_read_assigned` INT UNSIGNED NOT NULL DEFAULT '1', `sub_status` TINYINT UNSIGNED NOT NULL DEFAULT '1', `status` TINYINT UNSIGNED NOT NULL DEFAULT '1', `ended_by` INT UNSIGNED NULL, `updated_at` INT UNSIGNED NULL, `created_month_year` VARCHAR(7) NOT NULL, `created_at` INT UNSIGNED NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `chats_replies` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `chat_id` INT UNSIGNED NOT NULL, `user_id` INT UNSIGNED NOT NULL, `message` TEXT NOT NULL, `replied_at` INT UNSIGNED NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB;
INSERT INTO `permissions` (`id`, `name`, `access_key`) VALUES (NULL, 'Chats', 'chats'), (NULL, 'All Chats', 'all_chats');
INSERT INTO `permissions` (`id`, `name`, `access_key`) VALUES (NULL, 'Reports', 'reports');

// Live Chatting Module is Disabled by Default, Replace '0' with '1' to Enable it:
INSERT INTO `settings` (`id`, `access_key`, `value`) VALUES (NULL, 'sp_live_chatting', '0');

// If You've Added Any Permissions Other than the Default Permissions of the Script, Please Assign the Permissions to the Super Admin and Agent Roles Manually (Through the Admin Panel) Instead of Running These Three Queries:
INSERT INTO `roles_permissions` (`id`, `role_id`, `permission_id`) VALUES (NULL, '1', '15'), (NULL, '1', '16');
INSERT INTO `roles_permissions` (`id`, `role_id`, `permission_id`) VALUES (NULL, '2', '15');
INSERT INTO `roles_permissions` (`id`, `role_id`, `permission_id`) VALUES (NULL, '1', '17');

ALTER TABLE `chats_replies` ADD `area` TINYINT UNSIGNED NOT NULL DEFAULT '2' AFTER `message`;
INSERT INTO `email_templates` (`id`, `title`, `subject`, `hook`, `language`, `template`, `is_built_in`, `updated_at`, `created_at`) VALUES (NULL, 'Department Chat', 'New Chat Assigned to Department: {DEPARTMENT_NAME}', 'department_chat', 'english', '<p>Hi {USER_NAME},<br><br>A new chat has been assigned to your <b>{DEPARTMENT_NAME}</b> department.<br><br>You can see the assigned chat by clicking on the following link:<br><a href=\"{CHAT_URL}\" target=\"_blank\">Click here</a><br><br>Regards,<br>{SITE_NAME} Support</p>', '1', NULL, '1638553679');
CREATE TABLE IF NOT EXISTS `reports` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `users` INT UNSIGNED NOT NULL, `opened_tickets` INT UNSIGNED NOT NULL, `closed_tickets` INT UNSIGNED NOT NULL, `solved_tickets` INT UNSIGNED NOT NULL, `total_tickets` INT UNSIGNED NOT NULL, `active_chats` INT UNSIGNED NOT NULL, `ended_chats` INT UNSIGNED NOT NULL, `total_chats` INT UNSIGNED NOT NULL, `period` VARCHAR(255) NOT NULL, `generated_at` INT UNSIGNED NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE `tickets` ADD `security_key` VARCHAR(255) NOT NULL AFTER `department_id`;
ALTER TABLE `tickets` ADD `email_address` VARCHAR(255) NOT NULL AFTER `security_key`;
ALTER TABLE `tickets_replies` CHANGE `user_id` `user_id` INT(10) UNSIGNED NULL DEFAULT NULL;
INSERT INTO `email_templates` (`id`, `title`, `subject`, `hook`, `language`, `template`, `is_built_in`, `updated_at`, `created_at`) VALUES (NULL, 'Ticket Created (Unregistered User)', 'New Ticket Created For You', 'ticket_created_unregistered_user', 'english', '<p>Dear Customer,<br><br>A new ticket has been created for you by our support agent.<br><br>You can reach that ticket by clicking on the following link:<br><a href=\"{TICKET_URL}\" target=\"_blank\">Click here</a><br><br>Regards,<br>{SITE_NAME} Support</p>', '1', NULL, '1638868973');
ALTER TABLE `tickets` ADD `last_reply_area` TINYINT UNSIGNED NULL DEFAULT NULL AFTER `reopened_awaiting`;
INSERT INTO `email_templates` (`id`, `title`, `subject`, `hook`, `language`, `template`, `is_built_in`, `updated_at`, `created_at`) VALUES (NULL, 'Chat Assigned', 'Chat Assigned', 'chat_assigned', 'english', '<p>Hi {USER_NAME},<br><br>You have been assigned a chat. You can see the chat by clicking on the following link:<br><a href=\"{CHAT_URL}\" target=\"_blank\">Click here</a><br><br>Regards,<br>{SITE_NAME} Support</p>', '1', NULL, '1639160537');